#ifndef __KORO_CARD_H__
#define __KORO_CARD_H__

#include "main.h"
#include "jdy25m.h"
#include "ch8001.h"
#include "rc522.h"
#include "ws2812.h"

// 蓝牙 mesh
#define KORO_MESH_NET_ID            "2568"
#define KORO_MESH_STAFF_ADDR        "0005"
#define KORO_MESH_STAFF_DEVTYPE     JDY25M_DEVTYPE_ROUTE
#define KORO_MESH_STAFF_NAME        "Staff"

// 以下动画标志位必须加上偏移才能正确调用
#define KORO_A_OFFSET                2

#define KORO_A_CLEAR                 0
#define KORO_A_BLINK                 1
#define KORO_A_BREATHE               2

// 卡牌数据
struct koroCardDataStu {
    uint8_t id;

    union {
        uint16_t meshADDR_16;
        struct {
            uint8_t meshADDR_L;
            uint8_t meshADDR_H;
        }meshADDR_8;
    }meshAddrU;
    
    uint8_t meshData;

    uint8_t audioFolder;
    uint8_t audioIndex;
};

struct koroCardStu {
    struct ch8001Stu *ch;
    struct rc522Stu *rc;
    struct jdy25mStu *jdy;
    struct ws2812Stu *ws;
};

struct koroAnimeStu {
    uint8_t anime;
    uint8_t ForT; // 频率或周期
    uint8_t seconds; // 给 0 表示一直播放
    
    struct ws2812PixelDescribeStu rgb888;
};


uint8_t koro_analyze_data(struct koroCardStu *koro, struct koroCardDataStu *cardData);
int koro_read_card(struct koroCardStu *koro, struct koroCardDataStu *cardData);
int koro_write_card(struct koroCardStu *koro, struct koroCardDataStu *cardData);

uint16_t koro_anime_blink(struct ws2812Stu *ws, uint8_t freq, struct ws2812PixelDescribeStu *rgb888);
uint16_t koro_anime_breathe(struct ws2812Stu *ws, uint8_t period, struct ws2812PixelDescribeStu *rgb888);

void koro_anime_play(struct koroAnimeStu *anime);

#endif
